<?php
/**
 * Hy - 扩展系统函数库
 *
 * 系统扩展，不可可独立于系统运行的函数
 *
 * Copyright (c) 2013 YinHailin All rights reserved.
 * @Author: YinHailin
 * @Authorize: Boren Network
 * @Created by YinHailin at 2013-11-20
 */

/*
 * 获取真实数据表名
 * @param string $table 要进行转义的字符串
 * @return string
 */
function get_real_table($table) {
	$table = parse_name($table);
	$table = C('DB_PREFIX').$table;
	return $table;
}

/*
 * 获取用户权限样式
 * @param string $purview 用户权限字符串
 * @return string
 */
function get_purview($purview, $tree) {
	$purviewArray = explode(',', $purview);
	foreach ($tree as $key => $value) {
		if (in_array($key, $purviewArray)) {
			$tree[$key]['status'] = '1';
		} else {
			$tree[$key]['status'] = '0';
		}
	}
	return $tree;
}

/*
 * 标记数据在聚合标签中不存在的标签
 * @param string $string 数据中的聚合标签字符串
 * @param string $tagsArray 聚合标签
 * @return array
 */
function format_tags($string, $tagsArray) {
	foreach ($tagsArray as $key => $value) {
		$find = '|'.$key.',';
		if (strpos($string, $find) === false) {
			$array[] = array(
				'id' => $key,
				'tag' => $value,
				'status' => '0',
			);
		} else {
			$array[] = array(
				'id' => $key,
				'tag' => $value,
				'status' => '1',
			);
		}
	}
	return $array;
}